package appVeterinaria.servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import appVeterinaria.excepcion.DAOExcepcion;
import appVeterinaria.negocio.GestionCitas;
import appVeterinaria.negocio.GestionPaciente;

/**
 * Servlet implementation class CitaInsertarServlet
 */
@WebServlet("/CitaInsertarServlet")
public class CitaInsertarServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

    /**
     * Default constructor. 
     */
    public CitaInsertarServlet() {
    	super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
				//int idCli = Integer.parseInt(request.getParameter("id_cliente"));
				
				int idCita = Integer.parseInt(request.getParameter("idCita"));
				String fecha_cita = request.getParameter("fecha_cita");
				String diagnostico = request.getParameter("diagnostico");
				int idDoctor = Integer.parseInt(request.getParameter("idDoctor"));
				int idPaciente = Integer.parseInt(request.getParameter("idPaciente"));
				int idCliente = Integer.parseInt(request.getParameter("idCliente"));
				String receta = request.getParameter("receta");
				
				GestionCitas negocio = new GestionCitas();
				
				try {
					negocio.insertar(idCita, fecha_cita, diagnostico, idDoctor, idPaciente, idCliente, receta);
					response.sendRedirect(request.getContextPath()	+ "/CitaInsertarServlet");
				} catch (DAOExcepcion e) {
					RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
					rd.forward(request, response);
				}
	}

}
